﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace ESpace
{
    [ToolboxBitmap(typeof(ETextBox), "ETextBox.bmp")]
    [DefaultEvent("txbTextChanged")]
    public partial class ETextBox : UserControl
    {
        public ETextBox()
        {
            InitializeComponent();
        }

        #region *** события txb ********************************************
        public event EventHandler txbTextChanged;
        private void txb_TextChanged(object sender, EventArgs e)
        {
            if (txbTextChanged != null) txbTextChanged(this, e);
        }   
        public event KeyEventHandler txbKeyDown;
        private void txb_KeyDown(object sender, KeyEventArgs e)
        {
            if (txbKeyDown != null) txbKeyDown(this, e);
            if (ExitByEsc && e.KeyCode == Keys.Escape)
                Exit();
        }
        public event KeyPressEventHandler txbKeyPress;
        private void txb_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (txbKeyPress != null) txbKeyPress(this, e);
        }
        public event KeyEventHandler txbKeyUp;
        private void txb_KeyUp(object sender, KeyEventArgs e)
        {
            if (txbKeyUp != null) txbKeyUp(this, e);
        }
        public event EventHandler txbMouseLeave;
        private void txb_MouseLeave(object sender, EventArgs e)
        {
            if (txbMouseLeave != null) txbMouseLeave(this, e);
        }
        public event EventHandler txbMouseEnter;
        private void txb_MouseEnter(object sender, EventArgs e)
        {
            if (txbMouseEnter != null) txbMouseEnter(this, e);
        }
        public event MouseEventHandler txbMouseDown;
        private void txb_MouseDown(object sender, MouseEventArgs e)
        {
            if (txbMouseDown != null) txbMouseDown(this, e);
        }
        public event MouseEventHandler txbMouseMove;
        private void txb_MouseMove(object sender, MouseEventArgs e)
        {
            if (txbMouseMove != null) txbMouseMove(this, e);
        }
        public event MouseEventHandler txbMouseUp;
        private void txb_MouseUp(object sender, MouseEventArgs e)
        {
            if (txbMouseUp != null) txbMouseUp(this, e);
        }
        public event MouseEventHandler txbMouseWheel;
        private void txb_MouseWheel(object sender, MouseEventArgs e)
        {
            if (txbMouseWheel != null) txbMouseWheel(this, e);
        }
        #endregion *** события txb ********************************************

        bool pExitByEsc = true;
        [DefaultValue(true)]
        public bool ExitByEsc
        {
            get { return pExitByEsc; }
            set { pExitByEsc = value; }
        }

        public String Txt
        {
            get { return txb.Text; }
            set { txb.Text = value; }
        }

        public void Exit()
        {
            Color clr = txb.BackColor;
            txb.Enabled = false;
            txb.BackColor = clr;
        }

        private void ETextBox_MouseDown(object sender, MouseEventArgs e)
        {
            txb.Enabled = true;
            txb.Focus();
        }

    }
}
